<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/default}">
<head>
    <title>新增客户</title>
</head>
<body>
    <div layout:fragment="content">
        <div class="d-flex justify-content-between align-items-center mb-3">
            <h1>新增客户</h1>
            <a th:href="@{/customer/list}" class="btn btn-secondary">返回列表</a>
        </div>
        
        <div class="card">
            <div class="card-body">
                <form id="customerForm" data-validate="true" data-redirect="/crm/customer/list">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="name">客户名称</label>
                                <input type="text" class="form-control" id="name" name="name" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="phone">联系电话</label>
                                <input type="text" class="form-control" id="phone" name="phone" required>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="email">电子邮箱</label>
                                <input type="email" class="form-control" id="email" name="email">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="address">地址</label>
                                <input type="text" class="form-control" id="address" name="address">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="status">客户状态</label>
                                <select class="form-control" id="status" name="status">
                                    <option value="0" selected>潜在客户</option>
                                    <option value="1">正式客户</option>
                                    <option value="2">流失客户</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="level">客户等级</label>
                                <select class="form-control" id="level" name="level">
                                    <option value="1" selected>1星</option>
                                    <option value="2">2星</option>
                                    <option value="3">3星</option>
                                    <option value="4">4星</option>
                                    <option value="5">5星</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="source">客户来源</label>
                                <select class="form-control" id="source" name="source">
                                    <option value="网络搜索" selected>网络搜索</option>
                                    <option value="老客户推荐">老客户推荐</option>
                                    <option value="社交媒体">社交媒体</option>
                                    <option value="展会">展会</option>
                                    <option value="广告">广告</option>
                                    <option value="其他">其他</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="categoryId">客户类别</label>
                                <select class="form-control" id="categoryId" name="categoryId">
                                    <option value="1">重点客户</option>
                                    <option value="2" selected>普通客户</option>
                                    <option value="3">小客户</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="industry">所属行业</label>
                                <input type="text" class="form-control" id="industry" name="industry">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="scale">企业规模</label>
                                <select class="form-control" id="scale" name="scale">
                                    <option value="0" selected>小型企业</option>
                                    <option value="1">中型企业</option>
                                    <option value="2">大型企业</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="annualRevenue">年营业额</label>
                                <input type="text" class="form-control" id="annualRevenue" name="annualRevenue" value="0">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="website">网站</label>
                                <input type="url" class="form-control" id="website" name="website">
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label for="remarks">备注</label>
                                <textarea class="form-control" id="remarks" name="remarks" rows="3"></textarea>
                            </div>
                        </div>
                    </div>
                    
                    <div class="text-right">
                        <button type="submit" class="btn btn-primary">保存</button>
                        <a th:href="@{/customer/list}" class="btn btn-secondary ml-2">取消</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
    
    <th:block layout:fragment="scripts">
        <script>
            document.addEventListener('DOMContentLoaded', function() {
                // 初始化表单提交
                submitForm('customerForm', '/crm/api/customer/add');
                
                // 确保年营业额字段有值
                document.getElementById('customerForm').addEventListener('submit', function(e) {
                    const annualRevenueField = document.getElementById('annualRevenue');
                    if (!annualRevenueField.value || annualRevenueField.value.trim() === '') {
                        annualRevenueField.value = '0';
                    }
                });
            });
        </script>
    </th:block>
</body>
</html> 